import java.util.Stack;

class Solution {
    public static  int calPoints(String[] operations) {
        Stack<Integer> stack=new Stack<>();
        int i=0;
        for(;i<operations.length;i++){
            if(operations[i].equals("D")){
                stack.push(stack.peek()*2);
                continue;
            }
            if(operations[i].equals("C")){
                stack.pop();
                continue;
            }
            if(operations[i].equals("+")){
                int a=stack.pop();
                int b=stack.peek()+a;
                stack.push(a);
                stack.push(b);
                continue;
            }
            stack.push(Integer.parseInt(operations[i]));
        }
        int sum=0;
        for(Integer x:stack){
            sum+=x;
        }
        return sum;
    }


    public static void main(String[] args) {
        String[] ops = {"61","-50","65","+","D","-99","-58","88","19","-11"};
        System.out.println(calPoints(ops));

    }
}